package com.flash.BusinessParameters.controller;

import com.flash.BusinessParameters.entity.Security;
import com.flash.BusinessParameters.service.SecurityService;
import com.flash.demo.entity.UserDemo;
import com.flash.demo.service.UserDemoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 这是证券板块的控制层
 * @author 刘曦
 * @since 2022-8-9
 * @version 1.0
 */
@Controller
public class SecurityController {
    @Resource
    SecurityService securityService;


    /**
     * 查询出网页需要的数据
     * @param security 封装的板块对象
     * @return 返回的map里包含分页以及security集合
     */
    @RequestMapping("/selectSecurity")
    @ResponseBody
    public Map selectSecurity(Security security){
        HashMap map = new HashMap();
        //查询security集合
        List<Security> selectList = securityService.selectSec(security);
        //获得数据的总数
        int i = securityService.selectCountSecurity();
        for (int i1 = 0; i1 < selectList.size(); i1++) {
            if(selectList.get(i1).getSecurityType()==1){
                selectList.get(i1).setSecurity("股票");
            }else {
                selectList.get(i1).setSecurity("债券");
            }
            if (selectList.get(i1).getExchangeName()==1){
                selectList.get(i1).setExchange("深圳交易所");
            }else{
                selectList.get(i1).setExchange("上海交易所");
            }
        }
        map.put("code","0");
        map.put("msg","");
        map.put("count",i);
        map.put("data",selectList);
        return map;
    }

    /**
     * 添加证券的方法
     * @param security 存储证券数据的对象
     * @return 返回是否添加成功的字符串
     */
    @RequestMapping("/insertSecurity")
    public String insertSecurity(Security security){
        int i = securityService.insertSecurity(security);
        if (i>0){
            return "ok";
        }else {
            return "no";
        }
    }

    /**
     *修改证券数据的方法
     * @param security 封装证券数据的对象
     * @return 返回修改了多少条数据
     */
    @RequestMapping("toUpdateSecurity")
    public int updateSecurity(Security security){
        int i = securityService.updateSecurity(security);
        return i;
    }
    /**
     *删除数据的方法
     * @param securityId 根据Id删除数据
     * @return 返回删除了多少条数据
     */
    @RequestMapping("/deleteSecurity")
    public int deleteSecurity(String securityId){
        int i = securityService.deleteSecurity(securityId);
        return i;
    }
}
